<template>
<div v-if="isShow">
  <el-form ref="form" :model="form" label-width="22%" style="width: 60%">
    <el-form-item label="员工编号">
      <el-input type="number"  min="0" max="999" v-model="form.id"></el-input>
    </el-form-item>
    <el-form-item label="员工名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>

    <el-form-item label="员工密码">
      <el-input v-model="form.passwd"></el-input>
    </el-form-item>
    <el-form-item label="是否为管理员">
      <el-switch v-model="form.isManger"></el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="addEms">添加</el-button>
      <el-button type="primary" @click="upEms">修改</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import instance from "@/untils";

export default {
  data() {
    return {
      form: {
      },
    }
  },
  props:['isShow']
  ,
  methods: {
    toTra(){
      if(this.form.isManger){
        this.form.isManger=1;
      }else{
        this.form.isManger=0;
      }
    },
    addEms(){
      this.toTra();
      instance.post('/ems/addEms/',this.form).then(res=>{
        if(res.data.status==200){
          this.$message.success(res.data.msg)
        }else{
          this.$message.error(res.data.msg)
        }
      })
    },
    upEms(){
      this.toTra();
      instance.post('/updateEms',this.form).then(res=>{
        if(res.data.status==200){
          this.$message.success(res.data.msg)
        }else{
          this.$message.error(res.data.msg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>